<template>
  <div id="app">
    <transition :name="transitionName">
      <keep-alive>
          <router-view v-if="$route.meta.keepAlive" class="child-view"></router-view>
      </keep-alive>
    </transition>
   
    <transition :name="transitionName">
      <router-view  v-if="!$route.meta.keepAlive" class="child-view" ></router-view>
    </transition>
    
  </div>
</template>

<script>
export default {
  name: 'App', 
  data(){
    return{
      transitionName:'',
    }
  },
  watch: {
    '$route' (to, from) {
      if(from.name == 'Home'&& (to.name == 'My'||to.name == 'Pos')){
        this.transitionName = 'slide-fade'
      }else if(from.name == 'Pos' && (to.name == 'Home' || to.name == 'My')){
        this.transitionName = 'slide-fade'
      }else if(from.name =='My' && (to.name == 'Pos' || to.name == 'Home')){
        this.transitionName = 'slide-fade'
      }else{
        const toDepth = to.path.split('/').length
        const fromDepth = from.path.split('/').length
        this.transitionName = toDepth < fromDepth ? 'slide-left' : 'slide-right'
      }
      
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  //text-align: center;
  color: #2c3e50;
  width:100%;
  height:100%;
  min-height:100vh;
}
html,body{
  width:100%;
  height:100%;
}
p{
  margin:0;
}
.child-view {
 position: absolute;
 width: 100%;
 min-height: 100%;
 transition: all .5s ease;
 -webkit-transition: all .5s ease;
 -moz-transition: all .5s ease;
}
.slide-right-enter,.slide-left-leave-active {
 opacity: 0;
 transform: translate3d(50% 0, 0);
 -webkit-transform: translate3d(50%, 0, 0);
 -moz-transform: translate3d(50%, 0, 0);
}

.slide-left-enter,.slide-right-leave-active {
 opacity: 0;
 transform: translate3d(-50% 0, 0);
 -webkit-transform: translate3d(-50%, 0, 0);
 -moz-transform: translate3d(-50%, 0, 0);
}
.slide-fade-enter-active {
    transition: all .5s ease;
    -webkit-transition: all .5s ease;
    -moz-transition: all .5s ease;
    -ms-transition: all .5s ease;
    -o-transition: all .5s ease;
}
.slide-fade-leave-active {
    transition: all .5s ease;
    -webkit-transition: all .5s ease;
    -moz-transition: all .5s ease;
    -ms-transition: all .5s ease;
    -o-transition: all .5s ease;
}
.slide-fade-enter{
    opacity: 0;
    transform: translateX(25px);
    -webkit-transform: translateX(25px);
    -moz-transform: translateX(25px);
    -ms-transform: translateX(25px);
    -o-transform: translateX(25px);  
}
.slide-fade-leave-active {
    opacity: 0;
}
</style>
